package com.example.provider.listener;

import com.alibaba.fastjson.JSONObject;
import com.example.entity.UserTest;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

/**
 * @author tianzhuang
 * @version 1.0
 * @date 2021/11/7 23:38
 */
@Component
public class TestQueueListener {

    /**
     * work模式，消费队列中的消息
     * @param
     */
/*    @RabbitListener(queues = "testqueue")
    public void listen(String message) {
        System.err.println("this is provider1"+ message);
    }*/

    @RabbitListener(queues = "testqueue")
    private void listener2(Message msg) {
        String s = new String(msg.getBody());
        UserTest userTest = JSONObject.parseObject(s, UserTest.class);
        System.err.println("this is listener 1 接收到的消息为：" + userTest);
    }

    @RabbitListener(queues = "testqueuqe2")
    public void testqueue2Listen(Message msg) {
        String s = new String(msg.getBody());
        UserTest userTest = JSONObject.parseObject(s, UserTest.class);
        System.err.println("this is listener 1 接收到的消息为" + userTest);
    }

    @RabbitListener(queues = "testqueuqe3")
    public void testqueue2ListenByKey(Message msg) {
        String s = new String(msg.getBody());
        UserTest userTest = JSONObject.parseObject(s, UserTest.class);
        System.err.println("this is listener1" + userTest);
    }


    @RabbitListener(queues = "testqueuqe5")
    public void testqueue2ListenByTopic(Message msg) {
        String s = new String(msg.getBody());
        UserTest userTest = JSONObject.parseObject(s, UserTest.class);
        System.err.println("this is listener1" + userTest);
    }
}
